<%@page import="dao.UserManager"%>
<%@page import="model.User"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Virtual Intranet Library</title>
</head>
<body>
	<%@include file="home.jsp"%>
	<h2>Change password</h2>
	<%
		if (request.getParameter("submit") != null) {
			user.clearErrors();
			user.setPassword1(request.getParameter("password1"));
			user.setPassword2(request.getParameter("password2"));
			if (user.validatePassword()) {
				boolean result = UserManager.updateUser(user);
				if (result) {
					out.println("<h3>Password changed successfully.</h3>");
				} else {
					out.println("<h3>There was a problem changing the password.</h3>");
				}
			}
		}
	%>
	<form method="post">
		New password: <input type="password" name="password1">
		<%=user.getError("password1")%>
		<br> Confirm password: <input type="password" name="password2">
		<%=user.getError("password2")%>
		<br> <input type="submit" name="submit" value="Change">
	</form>
</body>
</html>